package com.backstage.service.impl;

import com.backstage.dao.GoodsMapper;
import com.backstage.pojo.Goods;
import com.backstage.service.GoodsService;
import com.backstage.utils.PageBean;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    public int selectGoodsTotal(){
        return goodsMapper.selectGoodsTotal();
    }

    public PageBean<Goods> selectGoodsList(int pageNum, int pageSize, String itemName){

        PageBean<Goods> pageBean = new PageBean<Goods>();

        Goods goods = new Goods();
        if(!"".equals(itemName)){
            goods.setGoodsname(itemName);
        }
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> goodsList = goodsMapper.selectGoodsList(goods);
        PageInfo<Goods> goodsPageInfo = new PageInfo<Goods>(goodsList);

        pageBean.setList(goodsList);
        pageBean.setPageBeanObj(goodsPageInfo.getPageNum(),goodsPageInfo.getPageSize(),goodsPageInfo.getNextPage(),goodsPageInfo.getPrePage(),goodsPageInfo.getTotal(),goodsPageInfo.getPages());

        return pageBean;

    }





}
